# -*- coding: utf-8 -*-
"""
Created on Mon Mar 11 17:36:31 2024

@author: heyuesong
"""


"""
DOM断点

"""
from Crypto.Cipher import ARC4
import requests
import pandas as pd
from utils import general

js = general.read_js(r'D:\code\猿人学\第63题.js')


result_list = []
for i in range(1,2):
    print(i)
    headers = {
        "authority": "www.python-spider.com",
        "accept": "*/*",
        "accept-language": "zh-CN,zh;q=0.9",
        "cache-control": "no-cache",
        "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
        "origin": "https://www.python-spider.com",
        "pragma": "no-cache",
        "referer": "https://www.python-spider.com/challenge/63",
        "sec-ch-ua": "\"Chromium\";v=\"122\", \"Not(A:Brand\";v=\"24\", \"Google Chrome\";v=\"122\"",
        "sec-ch-ua-mobile": "?0",
        "sec-ch-ua-platform": "\"Windows\"",
        "sec-fetch-dest": "empty",
        "sec-fetch-mode": "cors",
        "sec-fetch-site": "same-origin",
        "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36"
    }
    cookies = {
        "Hm_lvt_337e99a01a907a08d00bed4a1a52e35d": "1711520242,1711520884",
        "sessionid": "iog94pppgnk0diyvtmbvnqo5tg1bbnpp",
        "Hm_lpvt_337e99a01a907a08d00bed4a1a52e35d": "1711937260"
    }
    url = "https://www.python-spider.com/api/challenge63"
    data = js.call('window.call',i)
    
    key ='12345678912345678912345678912345'.encode()

    # 要加密的数据
    data = f'qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqf{i}'.encode()

    # 创建一个RC4 cipher对象
    cipher = ARC4.new(key)

    # 加密数据
    data = cipher.encrypt(data)
    response = requests.post(url, headers=headers, cookies=cookies, data=data,verify=False)
    result = response.text
    
    key ='12345678912345678912345678912345'.encode()
    # 创建另一个用于解密的cipher对象（使用相同的密钥）
    decipher = ARC4.new(key)

    # 解密数据
    decrypted_data = decipher.decrypt(response.content)
    

    print(result)

    result_list+=html
result_df = pd.DataFrame(result_list)

result_df['value'] = result_df['value'].apply(lambda x:int(x.replace('\r','')))


print(sum(result_df['value']))






from Crypto.Cipher import ARC4
from Crypto.Util.Padding import pad, unpad
from Crypto.Random import get_random_bytes

# 密钥应该是1到256字节长
key ='12345678912345678912345678912345'.encode()

# 要加密的数据
data = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaf1'.encode()

# 创建一个RC4 cipher对象
cipher = ARC4.new(key)

# 加密数据
encrypted_data = cipher.encrypt(data)



# 创建另一个用于解密的cipher对象（使用相同的密钥）
decipher = ARC4.new(key)

# 解密数据
decrypted_data = unpad(decipher.decrypt(encrypted_data), ARC4.block_size)

print("Original data:", data)
print("Encrypted data:", encrypted_data)
print("Decrypted data:", decrypted_data)
print("Decrypted data matches original?", data == decrypted_data)












